package com.selly.hanjuang.lib;

import java.util.ArrayList;
import java.util.HashMap;

import com.selly.hanjuang.MenuTransaksi;
import com.selly.hanjuang.R;
import com.selly.hanjuang.R.id;
import com.selly.hanjuang.R.layout;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListAdapterTransaksi extends BaseAdapter{
	
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;

	public ListAdapterTransaksi(Activity a, 
			ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = 
				(LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(
				activity.getApplicationContext());
	}
		
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, 
			View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View vi = convertView;
		if(convertView == null)
			vi = inflater.inflate(R.layout.item_list_rs, 
					null);
		
		TextView id_produk = (TextView) vi.findViewById(R.id.id_produk);
		TextView nama_produk = (TextView) vi.findViewById(R.id.nama_produk);
		TextView link_image_produk = (TextView) vi.findViewById(R.id.link_image_produk);
		TextView komposisi = (TextView) vi.findViewById(R.id.komposisi);
		TextView harga = (TextView) vi.findViewById(R.id.harga);
		ImageView thumb_image = (ImageView) vi.findViewById(R.id.image_produk);
		
		HashMap<String, String> daftar_rs = new HashMap<String, String>();
		daftar_rs = data.get(position);
		
		id_produk.setText(daftar_rs.get(MenuTransaksi.TAG_ID_PRODUK));
		nama_produk.setText(daftar_rs.get(MenuTransaksi.TAG_NAMA_PRODUK));
		link_image_produk.setText(daftar_rs.get(MenuTransaksi.TAG_LINK_IMAGE_PRODUK));
		komposisi.setText(daftar_rs.get(MenuTransaksi.TAG_KOMPOSISI));
		harga.setText(daftar_rs.get(MenuTransaksi.TAG_HARGA));
		imageLoader.DisplayImage(daftar_rs.get(MenuTransaksi.TAG_LINK_IMAGE_PRODUK), 
				thumb_image);
		
		return vi;
	}

}
